//
//  LMAddressFrameModel.m
//  MeetCard
//
//  Created by longmin on 16/12/2.
//  Copyright © 2016年 timtian. All rights reserved.
//

#import "LMAddressFrameModel.h"
#import "LMAddressModel.h"
#import "NSString+Extention.h"

@implementation LMAddressFrameModel

+(instancetype)addressFrameWithModel:(LMAddressModel *)addressModel {
    
    LMAddressFrameModel *frameModel = [[LMAddressFrameModel alloc] init];
    
    frameModel.addressModel = addressModel;
    
    [frameModel setLayout];
    
    return frameModel;
}

-(void)setLayout {
    
    CGSize nameSize = [self.addressModel.name sizeWithAttributes:@{NSFontAttributeName : _kFont32}];
    self.nameFrame = CGRectMake(MK_PADDING_30 * __kwRatio,
                                MK_PADDING_30 * __kwRatio,
                                nameSize.width,
                                nameSize.height);
    
    CGSize phoneSize = [self.addressModel.phone sizeWithAttributes:@{NSFontAttributeName : _kFont32}];
    self.phoneFrame = CGRectMake(CGRectGetMaxX(self.nameFrame) + MK_PADDING_10,
                                 self.nameFrame.origin.y,
                                 phoneSize.width,
                                 phoneSize.height);
    
    CGSize addSize = [self.addressModel.address boundingRectWithSize:CGSizeMake(__kScreenWidth - MK_PADDING_30 * __kwRatio * 2, CGFLOAT_MAX)
                                                             options:NSStringDrawingUsesLineFragmentOrigin
                                                          attributes:@{NSFontAttributeName : _kFontMain}
                                                             context:nil].size;
    self.addressFrame = CGRectMake(self.nameFrame.origin.x,
                                   CGRectGetMaxY(self.nameFrame) + MK_PADDING_20 * __kwRatio,
                                   addSize.width,
                                   addSize.height);
    
    self.lineFrame = CGRectMake(self.addressFrame.origin.x,
                                CGRectGetMaxY(self.addressFrame) + MK_PADDING_20,
                                __kScreenWidth - MK_PADDING_30 * __kwRatio ,
                                0.5);
    
    self.rowHeight = CGRectGetMaxY(self.lineFrame) + 40;
    
}

@end
